﻿using Sustainalytics.Download.Entities;
using Sustainalytics.Download.GridFs;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration.Abstractions;
using System.Windows;
using System.Windows.Controls;

namespace Sustainalytics.Download.View
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static readonly string ClientPlatform = "ClientPlatform";
        private static DownloadFromGridFs downloadInstance;
        private ViewModel viewModel;

        public MainWindow()
        {
            InitializeComponent();

            InitializeSimpleInjector();

            viewModel = new ViewModel(downloadInstance);

            InitializeElements();

            this.DataContext = viewModel;
        }

        private static void InitializeSimpleInjector()
        {
            var clientPlatform = ConfigurationManager.Instance.ConnectionStrings[ClientPlatform].ConnectionString;

            var dictionary = new Dictionary<string, string>() {
                {  ClientPlatform, clientPlatform }
            };

            var container = SimpleInjectorConfig.Register(dictionary);

            downloadInstance = container.GetInstance<DownloadFromGridFs>();
        }

        private void InitializeElements()
        {
            viewModel.PageSizes = new List<int>() { 10, 20, 50 };
            viewModel.FileList = new ObservableCollection<GridFsFile>(downloadInstance.GetFilesList(viewModel.Page, viewModel.Take).Result);
            viewModel.FilesCount = downloadInstance.GetFilesCount().Result;
        }
    }
}